from __future__ import with_statement
import os, re
import sys

# '/' works in windows to, it just looks weird between all '\'
if sys.platform == "win32":
    separator = '\\'
else:
    separator = '/'

# modify this regexp to support more file formats
fileexp = re.compile("\S+\.(c|cpp|h|hpp|cs|fx|py|java|asm|s)\Z")
dontcountexp = re.compile(".*?DONTCOUNT.*")
totallines = 0

for root, dirs, files in os.walk(''):
    if root == '':
        path = '.' + separator
    else:
        path = root + separator

    for file in files:
        if fileexp.match(file) != None:
            with open(path + file) as f:
                # Skip counting lines if there is DONTCOUNT in first line.
                if dontcountexp.match(f.readline()) == None:
                    # We've already read one line by matching it to dountcountexp.
                    lines = 1
                    for line in f:
                        lines += 1
                else:
                    lines = 0
            print path + file + " : "+ str(lines)
            totallines += lines
print "Total lines: " + str(totallines)
input()
